package utils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;


public class DBConnection {
	public Connection conn = null;
	public DBConnection(){
		this.connect();
	}
	
	public Connection getConn(){
		return this.conn;
	}
	
	public boolean connect(){
		try{
			Class.forName("com.mysql.jdbc.Driver").newInstance();
//			this.conn = java.sql.DriverManager.getConnection("jdbc:mysql://192.168.1.221:3306/log?useUnicode=true&characterEncoding=utf-8","root","a75R@9ef");
			this.conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/raiyun?useUnicode=true&characterEncoding=utf-8","root","root");
//			this.conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/raiyun?useUnicode=true&characterEncoding=utf-8","root","a75R@9ef");
		}catch(Exception ex){
			ex.printStackTrace();
			return false;
		}
		return true;
	}
	public static void closeConnection(Connection con)
	{
		try{
			if(con!=null)
				con.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public static void closeStatement(Statement statement)
	{
		try{
			if(statement!=null)
				statement.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public static void closePreparedStatement(PreparedStatement statement)
	{
		try{
			if(statement!=null)
				statement.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public static void closeResultSet(ResultSet rs)
	{
		try{
			if(rs!=null)
				rs.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
